import 'package:finance_app/generated/json/base/json_convert_content.dart';
import 'package:finance_app/generated/json/base/json_field.dart';

class EmployeeContactEntity with JsonConvert<EmployeeContactEntity> {
  @JSONField(name: "data_type")
  String dataType;
  int id;
  @JSONField(name: "company_id")
  int companyId;
  @JSONField(name: "user_id")
  int userId;
  String name;
  String title;
  String nationality;
  String race;
  @JSONField(name: "martial_status")
  String martialStatus;
  @JSONField(name: "pass_type")
  String passType;
  @JSONField(name: "pr_started_at")
  dynamic prStartedAt;

  String gender;
  @JSONField(name: "gender_name")
  String genderName;
  String dob;
  @JSONField(name: "identity_number")
  String identityNumber;
  @JSONField(name: "employee_number")
  String employeeNumber;
  @JSONField(name: "employment_type")
  String employmentType;
  @JSONField(name: "salary_period")
  String salaryPeriod;
  @JSONField(name: "income_data")
  List<EmployeeContactIncomeData> incomeData;
  @JSONField(name: "deduction_data")
  List<EmployeeContactDeductionData> deductionData;
  @JSONField(name: "leave_data")
  List<EmployeeContactLeaveData> leaveData;
  @JSONField(name: "working_days_count")
  num workingDaysCount;
  @JSONField(name: "working_days")
  List<WorkingDayData> workingDays;
  @JSONField(name: "worker_levy")
  String workerLevy;
  @JSONField(name: "employee_leaves")
  List<EmployeeContactEmployeeLeaves> employeeLeaves;

  @JSONField(name: "joined_at")
  dynamic joinedAt;
  @JSONField(name: "confirmed_at")
  dynamic confirmedAt;
  @JSONField(name: "country_code")
  String countryCode;
  @JSONField(name: "phone_number")
  String phoneNumber;
  String email;
  @JSONField(name: "is_director")
  int isDirector;
  @JSONField(name: "address_country")
  String addressCountry;
  @JSONField(name: "address_city")
  String addressCity;
  @JSONField(name: "address_postal_code")
  String addressPostalCode;
  @JSONField(name: "address_line_1")
  String addressLine1;
  @JSONField(name: "address_line_2")
  dynamic addressLine2;
  @JSONField(name: "address_unit")
  String addressUnit;
  @JSONField(name: "emergency_contact_name")
  dynamic emergencyContactName;
  @JSONField(name: "emergency_contact_relationship")
  dynamic emergencyContactRelationship;
  @JSONField(name: "emergency_contact_country_code")
  dynamic emergencyContactCountryCode;
  @JSONField(name: "emergency_contact_phone_number")
  dynamic emergencyContactPhoneNumber;
  @JSONField(name: "bank_account_name")
  String bankAccountName;
  @JSONField(name: "bank_account_number")
  String bankAccountNumber;
  @JSONField(name: "bank_name")
  String bankName;
  @JSONField(name: "bank_branch_name")
  String bankBranchName;
  @JSONField(name: "bank_branch_code")
  String bankBranchCode;
  @JSONField(name: "resigned_at")
  dynamic resignedAt;
  @JSONField(name: "is_completed")
  int isCompleted;
  @JSONField(name: "action_count")
  int actionCount;
  @JSONField(name: "created_by")
  dynamic createdBy;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;

  String contribution;
  @JSONField(name: "contribution_amount")
  String contributionAmount;
  @JSONField(name: "bank_code")
  String bankCode;

  @JSONField(name: "identity_issued_at")
  String identityIssuedAt;
  @JSONField(name: "identity_expire_at")
  String identityExpireAt;

  bool get canGeneratePayslip {
    if (this.passType == null) return false;
    if (this.incomeData[0]?.amount == null) return false;
    if (this.workingDaysCount == null || this.workingDaysCount == 0)
      return false;
    if (this.employmentType == null) return false;
    if (this.passType == 'spr' && this.prStartedAt == null) return false;
    if ((this.passType == 'spr' || this.passType == 'singaporean') &&
        this.contribution == null) return false;
    if ((this.passType == 'sp' || this.passType == 'wp') &&
        this.workerLevy == null) return false;
    return true;
  }
}

class EmployeeContactIncomeData with JsonConvert<EmployeeContactIncomeData> {
  String name;
  num amount;
  @JSONField(name: "currency_code")
  String currencyCode;
  @JSONField(name: "cpf_payable")
  int cpfPayable;
  @JSONField(name: "wage_type")
  String wageType;
}

class EmployeeContactDeductionData
    with JsonConvert<EmployeeContactDeductionData> {
  String name;
  num amount;
  @JSONField(name: "currency_code")
  String currencyCode;
}

class EmployeeContactLeaveData with JsonConvert<EmployeeContactLeaveData> {
  String name;
  num amount;
}

class WorkingDayData with JsonConvert<WorkingDayData> {
  @JSONField(name: "is_working")
  int isWorking;
  @JSONField(name: "is_half_day")
  int isHalfDay;
}

class EmployeeContactEmployeeLeaves
    with JsonConvert<EmployeeContactEmployeeLeaves> {
  @JSONField(name: "data_type")
  String dataType;
  int id;
  @JSONField(name: "employee_id")
  int employeeId;
  String year;
  String type;
  num amount;
  @JSONField(name: "forward_amount")
  num forwardAmount;
  num total;
  num used;
  String status;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;

  String name;
}
